package com.baomidou.springboot.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.springboot.entity.Hssse;
import com.baomidou.springboot.mapper.HssseMapper;
import com.baomidou.springboot.service.HssseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 关于我们 服务实现类
 * </p>
 *
 * @author QQQ
 * @since 2018-06-19
 */
@Service
public class HssseServiceImpl implements HssseService {

    @Autowired
    private HssseMapper hssseMapper;

    @Override
    public void save(Hssse hssse) {
        hssse.setCreateDate(new Date());
        hssseMapper.insert(hssse);
    }

    @Override
    public void delete(String id) {
        hssseMapper.deleteById(id);
    }

    @Override
    public Hssse edit(String id) {
        return hssseMapper.selectById(id);
    }

    @Override
    public void update(Hssse hssse) {
        hssse.setModifyDate(new Date());
        hssseMapper.updateById(hssse);
    }

    @Override
    public Hssse view(String id) {
        return hssseMapper.selectById(id);
    }

    @Override
    public Page<Hssse> list(Page<Hssse> page, String search) {
        if (0 == page.getSize()) {
            page.setSize(10);
        }
        if (0 == page.getCurrent()) {
            page.setCurrent(1);
        }
        List<Hssse> hssseList = hssseMapper.findByDateDesc(page, search);
        page.setRecords(hssseList);
        return page;
    }

    @Override
    public void deleteBatch(List<String> ids) {
        if (null == ids) {
            return;
        }
        hssseMapper.deleteBatchIds(ids);
    }

    @Override
    public Hssse findById(String id) {
        return hssseMapper.selectById(id);
    }

    @Override
    public List<Hssse> findBySort() {
        return hssseMapper.findBySort();
    }
}
